package servlet;

import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import service.CityService;

/**
 * Create By IntelliJ IDEA
 *
 * @author: jsonor
 * @create-Time: 2017/10/17 10:18
 * @description: 删除city数据库表中的一条数据
 */
@WebServlet(name = "deleteSingle", urlPatterns = {"/deleteSingle"})
public class DeleteSingleServlet extends HttpServlet{

  @Override
  protected void doGet(HttpServletRequest request,
      HttpServletResponse response)
      throws ServletException, IOException {

    int id = Integer.parseInt(request.getParameter("id"));
    CityService service = new CityService();
    try {
      service.deleteById(id);
      response.sendRedirect( request.getContextPath() + "/displayPage?pageId="
        + request.getParameter("pageId"));
    } catch (Exception e) {
      request.setAttribute("error", e);
      request.getRequestDispatcher("/error.jsp").forward(request, response);
    }
  }
}
